import Vue from 'vue'
import App from './App'
import router from './router'
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/css/global.css'
import axios from 'axios'

Vue.config.productionTip = false

Vue.use(Element)

//配置与后端的通信
axios.defaults.baseURL= 'http://localhost:3000'
// axios.defaults.headers.post['Content-Type'] = "application/json"
// axios.defaults.withCredentials = true
axios.defaults.headers.common['Authorization'] = window.localStorage.getItem('token')
Vue.prototype.$axios = axios

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
//拦截数据包
axios.interceptors.request.use(config => {
  //判断是否存在token，如果存在将每个页面header都添加token
  if (localStorage.getItem('token')) {
    config.headers.Authorization = localStorage.getItem('token');
  }
  return config;
})
